package com.jcc.springcloud.service.impl;

import com.jcc.springcloud.common.utils.MD5Utils;
import com.jcc.springcloud.dao.RegisterDao;
import com.jcc.springcloud.service.RegisterService;
import com.jcc.springcloud.user.UserDo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RegisterServiceImpl implements RegisterService {
    @Resource
    private RegisterDao registerDao;

    @Override
    public List<UserDo> findUserByName(UserDo userDo){
        return registerDao.findUserByName(userDo);
    }

    @Override
    public int register(UserDo userDo) {
        List<UserDo> userList = findUserByName(userDo);
        System.out.println("listSize = "+userList.size());
        if(userList.size()==0){
            System.out.println("register = "+userDo.getUserName());
            String md5Pwd = MD5Utils.md5Encrypt32Lower(userDo.getPwdMd5().toString());
            userDo.setPwdMd5(md5Pwd);
            int result = registerDao.register(userDo);
            return 1;
        } else{
            return 0;
        }
    }
}
